package cn.edu.jxust.core.infrastructure.mapper;

import cn.edu.jxust.common.domain.entity.Site;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
import java.util.List;

/**
 * @author QiuKangming
 * @since 2020-07-06
 */

public interface SiteMapper extends BaseMapper<Site> {

    /**
     * 根据 id 获取监测点名称
     * @param id 监测点id号
     * @return String
     */
    @Select("SELECT site_detail_address FROM t_site WHERE id = #{id}")
    String getSiteDetailNameById(Integer id);

    /**
     * 根据区域id获取该区域的监测点列表
     * @param areaId 区域id
     * @return List<Integer>
     */
    @Select("SELECT id FROM t_site WHERE area_id = #{areaId} AND status = 1")
    List<Integer> getSiteIdsByAreaId(Integer areaId);

    /**
     * 根据区域id和企业id获取该企业的监测点列表
     * @param areaId 区域id
     * @param enterpriseId 企业id
     * @return List<Integer>
     */
    @Select("SELECT id FROM t_site WHERE area_id = #{areaId} AND enterprise_id = #{enterpriseId} AND status = 1")
    List<Integer> getSiteIdsByAreaIdAndEnterpriseId(Integer areaId, Integer enterpriseId);

    /**
     * 根据 区域id和企业id查询该企业下的监测点个数
     * @param areaId 区域id
     * @param enterpriseId 企业id
     * @return int
     */
    @Select("SELECT COUNT(1) FROM t_site WHERE area_id = #{areaId} AND enterprise_id = #{enterpriseId} AND status = 1")
    int checkSiteCountByAreaIdAndEnterpriseId(Integer areaId, Integer enterpriseId);

}
